<template>
  <div>
    <div class="topNav">
      <div class="nav">
        <div class="nav-item">
          <a href="/"> <i class="el-icon-arrow-left"></i>返回首页 </a>
        </div>
      </div>
      <div class="logo">
        <img src="~/static/index/logo-text.png" alt="" class="logo-img" />
      </div>
    </div>
    <div class="news">
      <div class="title">{{ name }}</div>
      <div class="time">{{ newsCreatedAt }}</div>
      <div class="content">
        <p v-html="content"></p>
        <p class="link">
          转载自：
          <a :href="url" target="_blank">{{ source }}</a>
        </p>
      </div>
    </div>
  </div>
</template>
  
  <script>
export default {
  layout:'layout',
  head() {
    return {
      title: this.name || "新闻",
    };
  },
  name: "siteNav",
  props: {
    componentContent: {
      type: Object,
    },
  },
  computed: {},
  async asyncData({ $indexApi, params }) {
    const id = params.id;
    const res = await $indexApi.getNewsById({
      id: id,
    });
    if (res.code == "0") {
      return {
        //评论列表
        name: res.data.name,
        content: res.data.content,
        url: res.data.url,
        source: res.data.source,
        newsCreatedAt: res.data.newsCreatedAt,
      };
    }
  },
  data() {
    return {
      id: "",
      name: "",
      content: "",
      url: "",
      source: "",
      newsCreatedAt: "",
    };
  },
  mounted() {
    window.scrollTo(0, 0);
    // this.id= this.$route.query.id;
    // this.getNewsById()
  },
  methods: {
    async getNewsById() {
      const res = await getNewsById({
        id: this.id,
      });
      if (res.data.code == 0) {
        this.name = res.data.name;
        this.content = res.data.content;
        // this.content=JSON.parse(this.content)
        this.url = res.data.url;
        this.source = res.data.source;
        this.newsCreatedAt = res.data.newsCreatedAt;
      }
    },
  },
};
</script>
  
</script>
  
<style lang="scss" scoped>
.topNav {
  width: 100%;
  height: 70px;
  margin: 0px auto;
  // padding: 0 96px;
  overflow: hidden;
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 5px 10px -5px rgba(0, 0, 0, 0.3);
  position: sticky;
  top: 0;
  .logo {
    margin-right: 62px;
    .logo-img {
      width: 168px;
      height: 48px;
    }
  }
  .nav {
    display: flex;
    .nav-item {
      height: 48px;
      margin-left: 38px;
      padding: 0 24px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 32px;
      font-weight: 500;
      letter-spacing: -0.14px;
      line-height: 24px;
      color: rgba(56, 56, 56, 1);
      a {
        text-decoration: none;
        color: #000;
      }
    }
    .login {
      display: flex;
      margin-left: 38px;
      align-items: center;
      padding-left: 6px;
      font-size: 14px;
      font-weight: 500;
      color: rgba(0, 0, 0, 0.56);
      .user {
        margin-left: 14px;
        width: 33px;
        height: 33px;
      }
    }
  }
}
.news {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  width: 1094px;
  margin: 0 auto;
  padding-top: 140px;
  .title {
    font-size: 48px;
    font-weight: 700;
    letter-spacing: 6px;
    line-height: 65px;
    color: rgba(13, 21, 46, 0.65);
    width: 970px;
    text-align: center;
  }
  .time {
    width: 1100px;
    text-align: center;
    margin-top: 10px;
    font-size: 24px;
    font-weight: 400;
    line-height: 30px;
    color: rgba(13, 21, 46, 0.65);
  }
  .content {
    font-size: 28px;
    font-weight: 400;
    letter-spacing: 0px;
    line-height: 50px;
    color: rgba(13, 21, 46, 0.65);
    // text-indent: 56px;
    // white-space:pre-wrap;
    p {
      margin: 0 !important;
    }
  }
  .link {
    text-align: end;
    a {
      // text-decoration: none;
      color: #999;
    }
  }
}
</style>